package mcsm.DataBaseIntegration;

import java.sql.SQLException;
import java.sql.Statement;

import mcsm.DataBaseInterface.DeleteOperation;

import Stragety.TotalStragety;

public class DeleteSumPreferential implements DeleteOperation {

	private TotalStragety sumPreferential;
	private int totalStraNum;
	
	public DeleteSumPreferential(TotalStragety sumPreferential) {
		this.sumPreferential = sumPreferential;
	}

	@Override
	public Boolean connect(Statement statement) {
		int i = 0;
		try {
			i = statement.executeUpdate(delete());
			statement.executeUpdate("update  number set sumPreferential = "  + totalStraNum);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return (i != 0);
	}

	@Override
	public String delete() {
		DataBaseConnect database = DataBaseConnect.getDatabase();
		totalStraNum = database.getSumPreferentialNumber() - 1;
		String id = sumPreferential.getID();
		String sql = "delete from sumPreferential where id = " + id;
		return sql;
	}

}
